package com.jcl.recruit.user.service;

import com.jcl.core.utils.StringUtils;
import com.jcl.recruit.core.constants.Constants;
import com.jcl.recruit.user.logic.UserExternalAccessLogic;
import com.jcl.recruit.user.logic.UserLogic;
import com.jcl.recruit.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.Map;


@Service
public class UserAuthorityService {

    @Autowired
    private UserLogic userLogic;

    @Autowired
    private UserExternalAccessLogic userExternalAccessLogic;

    /* *
     * @Author yyliu
     * @Description //TODO
     * @Date 10:44 2018/9/26
     * @Param [userToken]
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    public Map<String, Object> getUserAuthority(String userId) {

        Map<String, Object> map = new LinkedHashMap<>();
        if (StringUtils.hasLength(userId)) {
            User user = userLogic.findOneById(Integer.parseInt(userId));
            if (null != user) {
                Integer status = user.getStatus();
                map.put("roles", user.getRoles());
                map.put("status", status);
                map.put("statusName", Constants.UserInfo.getStatusName(status));
                if (Constants.UserInfo.USER_STATUS_UNACTIVE == status) {
                    User adminUser = userLogic.findAdminUserByCorp(user.getCorpCode());
                    if (null != adminUser) {
                        map.put("admin", adminUser.getRealname());
                        map.put("adminEmail", adminUser.getEmail());
                        map.put("adminPhoto", "");
                    }
                }
            }
        }
        return map;
    }

}
